package com.vito.dcs.asphalt.station.service.impl;

import java.util.*;
import org.springframework.beans.factory.annotation.*;

import com.vito.dcs.asphalt.station.model.MixAsphaltStationModel;
import com.vito.dcs.asphalt.station.service.MixAsphaltStationService;
import com.alibaba.dubbo.config.annotation.Service;
import com.vito.dcs.asphalt.device.dao.MixAsphaltBlenderMapper;
import com.vito.dcs.asphalt.pore.dao.MixAsphaltPoreMapper;
import com.vito.dcs.asphalt.station.dao.MixAsphaltStationMapper;
import com.vito.base.model.DataGrid;
import com.vito.base.factory.IDFactory;

/**
 * MixAsphaltStationService接口实现类
 * @author  lyhao E-mail: 
 * @version 0.0.1
 * @date    2019-4-12 17:08:17
 */
@Service
public class MixAsphaltStationServiceImpl implements MixAsphaltStationService {
	
	@Autowired
	private MixAsphaltStationMapper mixasphaltstationMapper;
	@Autowired
	private MixAsphaltBlenderMapper mixasphaltBlenderMapper;
	@Autowired
	private MixAsphaltPoreMapper mixasphaltPoreMapper;
	
	@Override
	public void saveMixAsphaltStation(MixAsphaltStationModel mixasphaltstation){
		  mixasphaltstation.setId(IDFactory.getIDFactory().getIdInc()+"");               
		mixasphaltstationMapper.saveMixAsphaltStation(mixasphaltstation);
	}
	@Override
	public DataGrid<MixAsphaltStationModel> queryMixAsphaltStationByPage(MixAsphaltStationModel mixasphaltstation){
		DataGrid<MixAsphaltStationModel> dg = new DataGrid<MixAsphaltStationModel>();
		dg.setRows(mixasphaltstationMapper.queryMixAsphaltStationByPage(mixasphaltstation));
		dg.setTotal(mixasphaltstation.getTotal());
		return dg;
	}
	@Override
	public MixAsphaltStationModel queryMixAsphaltStation(MixAsphaltStationModel mixasphaltstation){
		return mixasphaltstationMapper.queryMixAsphaltStation(mixasphaltstation);
	}
	@Override
	public MixAsphaltStationModel updateMixAsphaltStation(MixAsphaltStationModel mixasphaltstation){
		if(mixasphaltstationMapper.updateMixAsphaltStation(mixasphaltstation)>0){
			return mixasphaltstation;
		}else{
			return null;
		}
	}
	
	@Override
	public Integer deleteMixAsphaltStation(MixAsphaltStationModel mixasphaltstation){
		String[] stationIds = mixasphaltstation.getCheckeds();
		for (String stationId : stationIds) {
			mixasphaltPoreMapper.deleteMixAsphaltPoreByStationId(stationId);
			mixasphaltBlenderMapper.deleteMixAsphaltBlenderByStationId(stationId);
		}
		return mixasphaltstationMapper.deleteMixAsphaltStation(mixasphaltstation);
	}
	@Override
	public List<MixAsphaltStationModel> queryStationList() {
		return mixasphaltstationMapper.queryStationList();
	}

}